/********************************************************************************
*                 Copyright (C) 2011 - Las Venturas Playground                  *
*                      http://iv-mp.nl | http://lvp-iv.com                      *
*                                                                               *
*    This program is free software: you can redistribute it and/or modify       *
*    it under the terms of the GNU General Public License as published by       *
*    the Free Software Foundation, either version 3 of the License, or          *
*    (at your option) any later version.                                        *
*                                                                               *
*    This program is distributed in the hope that it will be useful,            *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of             *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
*    GNU General Public License for more details.                               *
*                                                                               *
*    You should have received a copy of the GNU General Public License          *
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
*                                                                               *
*********************************************************************************
*                                                                               *
*  Las Venturas Playground - Commands/playerCommands.nut                        *
*                                                                               *
*  This file will hold all player commands.                                     *
*                                                                               *
********************************************************************************/

local cmdHandler = CommandHandler();

/**
 * This is the /help command, giving some basic information.
 * @author: Sander <sander@sa-mp.nl>
 *
 * @param playerid The playerid that used the command.
 * @param commandParams The parameters passed on to the command.
 * @param commandText The entire command as a string.
 */
local function cmdHelp (playerid, cmdWords, cmdStr)
{
    sendPlayerMessage (playerid, "* Check /commands for a command list.", COLOR_WHITE);
    sendPlayerMessage (playerid, "* Please read /rules and /credits.", COLOR_WHITE);
}

cmdHandler.registerCommand ("/help", Command (cmdHelp), COMMAND_LEVEL_PLAYER);

/**
 * /commands, it shows a list of all available commands.
 * @author: Sander <sander@sa-mp.nl>
 *
 * @param playerid The playerid that used the command.
 * @param commandParams The parameters passed on to the command.
 * @param commandText The entire command as a string.
 */
local function cmdCommands (playerid, cmdWords, cmdStr)
{
    sendPlayerMessage (playerid, "The following commands are available:", COLOR_RED);
    sendPlayerMessage (playerid, "/carteleport, /help, /kill, /vehicle, /teleport, /vr, /weapon", COLOR_WHITE);
}

cmdHandler.registerCommand ("/commands", Command (cmdCommands), COMMAND_LEVEL_PLAYER);

/**
 * This is the /ctp or /carteleport command,
 * it allows player to teleport with a car to a certain person.
 * @author: Sander <sander@sa-mp.nl>
 *
 * @param playerid The playerid that used the command.
 * @param commandParams The parameters passed on to the command.
 * @param commandText The entire command as a string.
 */
local function cmdCarTeleport (playerid, cmdWords, cmdStr)
{
    if (cmdWords.len () < 2) 
    {
        sendPlayerUsageMessage( playerid, "/ctp [PlayerID or playername]" );
        return;
    }
    
    if (!isPlayerInAnyVehicle (playerid))
    {
        sendPlayerErrorMessage( playerid, "Forgot your vehicle?" );
        return;
    }
    
    local targetPlayer = getPlayerFromInput (cmdWords[1]);

    if (targetPlayer == playerid)
    {
        sendPlayerErrorMessage (playerid, "You can't car-teleport to yourself!");
        return;
    }
    
    if (targetPlayer < 0) 
    {
        sendInvalidPlayerMessage (playerid, targetPlayer);
        return;
    }
    
    local VehPos = getPlayerCoordinates (targetPlayer);
    setVehicleCoordinates(getPlayerVehicleId (playerid), VehPos[0], VehPos[1], VehPos[2] + 2.0);
    sendPlayerMessage(playerid, "* You have been car-teleported to " + getPlayerName (targetPlayer), COLOR_GREEN );
}

cmdHandler.registerCommand ("/ctp", Command (cmdCarTeleport), COMMAND_LEVEL_PLAYER);
cmdHandler.registerCommand ("/carteleport", Command (cmdCarTeleport), COMMAND_LEVEL_PLAYER);

/**
 * The /kill command, makes the player commit suicide.
 * @author: Sander <sander@sa-mp.nl>
 *
 * @param playerid The playerid that used the command.
 * @param commandParams The parameters passed on to the command.
 * @param commandText The entire command as a string.
 */
local function cmdKill (playerid, cmdWords, cmdStr)
{
    setPlayerHealth (playerid, -1);
}

cmdHandler.registerCommand ("/kill", Command (cmdKill), COMMAND_LEVEL_PLAYER);

/**
 * The /teleport command, allowing users to teleport to another.
 * @author: Sander <sander@sa-mp.nl>
 *
 * @param playerid The playerid that used the command.
 * @param commandParams The player to teleport to.
 * @param commandText The entire command as a string.
 */
local function cmdTeleport (playerid, cmdWords, cmdStr)
{
    if (cmdWords.len () < 2) 
    {
        sendPlayerUsageMessage (playerid, "/tp [PlayerID or playername]");
        return;
    }
    
    local targetPlayer = getPlayerFromInput (cmdWords[1]);
    
    if (targetPlayer == playerid)
    {
        sendPlayerErrorMessage (playerid, "You can't teleport to yourself!");
        return;
    }
    
    if (targetPlayer < 0) 
    {
        sendInvalidPlayerMessage (playerid, targetPlayer);
        return;
    }
    
    local aPlayerPos = getPlayerCoordinates (targetPlayer);
    setPlayerCoordinates (playerid, aPlayerPos[0], aPlayerPos[1], aPlayerPos[2]);
    sendPlayerMessage (playerid, "* You have been teleported to " + getPlayerName (targetPlayer) + ".", COLOR_GREEN );
    setCameraBehindPlayer (playerid);
}

cmdHandler.registerCommand ("/tp", Command (cmdTeleport), COMMAND_LEVEL_PLAYER);
cmdHandler.registerCommand ("/teleport", Command (cmdTeleport), COMMAND_LEVEL_PLAYER);
